#include"UserRecord.h"
USING_NS_CC;
using namespace std;

UserRecord::UserRecord(const std::string& userId)
{
	setUserId(userId);
}

UserRecord::~UserRecord()
{
}

void UserRecord::SaveToUserDefault()
{
	char buff[100] = { 0 };
	sprintf(buff, "%d %d %d", getCoin(), getExp(), getLife());
	CCUserDefault::sharedUserDefault()->setStringForKey(m_userId.c_str(), buff);
}

void UserRecord::ReadFromUserDefault()
{
	if (CCUserDefault::sharedUserDefault()->isXMLFileExist())
	{
		string xml = CCUserDefault::sharedUserDefault()->getStringForKey(m_userId.c_str());
		int coin;
		int exp;
		int life;
		sscanf(xml.c_str(), "%d %d %d", coin, exp, life);
		setCoin(coin);
		setExp(exp);
		setLife(life);
	}
}
